package com.simple.datax.dao.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.simple.base.dao.BaseDAO;
import com.simple.datax.dao.IDataxFlowActivityTemplateDAO;
import com.simple.datax.vo.DataxFlowActivityTemplateIdVO;
import com.simple.datax.vo.DataxFlowActivityTemplateVO;

@Repository("dataxFlowActivityTemplateDAO")
public class DataxFlowActivityTemplateDAOImpl extends BaseDAO implements
		IDataxFlowActivityTemplateDAO {

	@Override
	public DataxFlowActivityTemplateVO findById(DataxFlowActivityTemplateIdVO id) {
		return super.get(DataxFlowActivityTemplateVO.class, id);
	}

	@Override
	public void saveOrUpdate(DataxFlowActivityTemplateVO dataxFlowActivityTemplateVO ) {
		super.saveOrUpdate(dataxFlowActivityTemplateVO);
	}

	@Override
	public void update(DataxFlowActivityTemplateVO dataxFlowActivityTemplateVO) {
		super.saveOrUpdate(dataxFlowActivityTemplateVO);
	}

	@Override
	public List<DataxFlowActivityTemplateVO> findAll() {
		return super.query(DataxFlowActivityTemplateVO.class);
	}

	@Override
	public void delete(DataxFlowActivityTemplateVO dataxFlowActivityTemplateVO) {
		super.delete(dataxFlowActivityTemplateVO);
	}

	@Override
	public void delete(DataxFlowActivityTemplateIdVO id) {
		super.delete(DataxFlowActivityTemplateVO.class,id);
	}

	@Override
	public Integer generateId() {
		List<?> list =  getSession().createSQLQuery("select seq_flow_activity_id.nextval from dual").list();
		return ((BigDecimal)list.get(0)).intValue();
	}

	@Override
	public void addBatch(
			List<DataxFlowActivityTemplateVO> listDataxFlowActivityTemplateVO) {
		super.saveOrUpdate(listDataxFlowActivityTemplateVO);
	}

	@Override
	public List<DataxFlowActivityTemplateVO> findByFlowTempId(String flowTempId) {
		String hql="from DataxFlowActivityTemplateVO d where 1>0 and d.id.flowTemplateId=? order by d.id.activityNo asc ";
		return super.query(hql, flowTempId);
	}

	@Override
	public void deleteByFlowTemplateId(String flowTemplateId) {
		String hql="delete from DataxFlowActivityTemplateVO d where d.id.flowTemplateId=? ";
		final List<String> paramList = new ArrayList<String>();
		paramList.add(flowTemplateId);
		super.executeUpdate(hql, paramList);
		
	}
}
